package ca.bcit.comp3910;

import java.io.Serializable;
import java.util.ArrayList;

import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;


import ca.bcit.comp3910.access.EmployeeManager;
import ca.bcit.comp3910.model.Employee;

/**
 * 
 * View class to interact between the Superuser and the JSF
 * 
 * @author Ivy Cheung, Stacy Mitchell
 * @version 2.0
 * 
 */
@SuppressWarnings("serial")
@Named
@SessionScoped
public class Superuser implements Serializable {
    /**
     * Employee Manager
     */
    @Inject
    private EmployeeManager em;

    /**
     * Employee ID
     */
    private Integer empID;
    /**
     * Employee Password
     */
    private String password;
    /**
     * Employee Name
     */
    private String empName;
    /**
     * Superuser
     */
    private boolean superUser;

    /**
     * Checks if superuser is logged in.
     * 
     * @return boolean true if logged in, false if not
     */
    public boolean isSuperUserLoggedIn() {
        if (em.isSuperUser(empID)) {
            return true;
        }
        return false;
    }

    /**
     * Adds user to employee roster
     * 
     * @return string this determines which page will be redirected next
     */
    public String addUser() {
        if (em.createEmployee(empID, new Employee(empID, password, empName,
                superUser))) {
            empID = 0;
            password = null;
            empName = null;
            superUser = false;
            return "success";
        }
        return null;
    }

    /**
     * Deletes a user from the employee roster?
     * 
     * @param emp
     *            an employee
     * @return string this determines which page will be redirected next
     */
    public String deleteUser(Employee emp) {
        if (em.deleteEmployee(emp.getEmpID())) {
            return "success";
        }
        return null;
    }

    /**
     * Update a user in the employee roster?
     * 
     * @param emp
     *            an Employee
     * @return string this determines which page will be redirected next
     */
    public String updateUser(Employee emp) {
        if (em.updateEmployee(emp.getEmpID(), new Employee(emp.getEmpID(), emp.getPassword(), emp.getEmpName(), false))) {
            return "success";
        }
        return null;
    }

    /**
     * Gets a list of employees
     * 
     * @return idList
     */
    public ArrayList<Employee> getNames() {
        ArrayList<Employee> idList = em.getAllEmpID();
        return idList;
    }

    /** 
     * Getters and setters
     */
    public Integer getEmpID() { return empID; }
    public void setEmpID(Integer empID) { this.empID = empID; }

    public String getPassword() { return password; }
    public void setPassword(String password) { this.password = password; }

    public String getEmpName() { return empName; }
    public void setEmpName(String empName) { this.empName = empName; }

    public boolean isSuperUser() { return superUser; }
    public void setSuperUser(boolean superUser) { superUser = false; }
}
